/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hitechbangla.fctu.base.aircraft;

import com.hitechbangla.fctu.base.GameScene;
import com.hitechbangla.fctu.base.Location;
import com.hitechbangla.fctu.base.radar.Detected;
import com.hitechbangla.fctu.base.radar.Radar;
import fctu.simulator.HTB_MAIN;
import java.awt.Point;
import java.awt.geom.Point2D;


/**
 *
 * @author HTB BIKASH
 */


public class DragAircraft{
    
    Point2D point2;
    public Aircraft aircraft;    
    GameScene gamescene;
    public Radar radar;
    private final int range = 40;
    private static int phase=0;
    

    public DragAircraft(GameScene gameScene, Point2D point) {
                                   
        
        
        
        double pointx = (point.getX()*HTB_MAIN.one_nm_equivalent_pixel);
        double pointy = (point.getY()*HTB_MAIN.one_nm_equivalent_pixel);
        
        this.point2 = new Point2D.Double(pointx, pointy);
        
        
        for(Aircraft airraft : gameScene.airCraftList)
	{   
           
	   if(withinRange(airraft,point2))
	    {					
		aircraft = airraft;
		phase = 1; // one aircraft selected
                
                if(phase ==1)
                {
                    double ax1 = point2.getX();
                    double ay1 = point2.getY();
                    double az1 = aircraft.getAircraftState().getLocation().getZ();
                    Location loc2 = new Location(ax1, ay1, az1);

                    aircraft.getAircraftState().setLocation(loc2);
                    phase = 0;                  
                }                       
              
	    }           
	
	}
        
    }
    
    // this method is same as AutoLock, we have to improvise the structure, like by polymorphism
    private boolean withinRange(Aircraft aircraft, Point2D point)
    {	      
        
	Point2D point3 = new Point2D.Double();
        point3.setLocation(point.getX(), point.getY());
        
	double distX = Math.abs((double)point2.getX() - aircraft.getAircraftState().getLocation().getX());
        
	double distY = Math.abs((double)(point2.getY() - aircraft.getAircraftState().getLocation().getY()));
        
	return (distX<range && distY <range);	
    }       
    
   
}
